import React, { Component, PureComponent, Suspense, lazy } from 'react'


import { Button, Modal } from 'antd';

class ReactInstanceWrap extends PureComponent {

  instanceRef = React.createRef()

  state = {
    visible: true
  }



  okDo = () => {
    const { callback } = this.props
    typeof callback === 'function' && callback(this)
  }

  render() {
    const { visible } = this.state
    const {
      title = '标题',
      width = '800px',
      bodyStyle = { height: '460px' },
      reactInstance
    } = this.props

    let Comp = reactInstance

    // if (!Comp.prototype instanceof  Component ) {      // 为  true 为 class 类组件， 否则 是 函数 组件
    //   console.log(1)
    //   Comp = React.forwardRef
    // }

    return (
      <>
        <Modal
          title={title}
          width={width}
          centered
          bodyStyle={bodyStyle}
          visible={visible}
          destroyOnClose={true}
          onCancel={() => { this.setState({ visible: false }) }}
          onOk={this.okDo}
        >
          <Comp {...this.props} ref={this.instanceRef}/>
        </Modal>
      </>
    )
  }

}

export default ReactInstanceWrap